/* 
 * Gneat (http://gneat.org)
 *
 * (C) Copyright 2011 and beyond - Claudio Stella, all rights reserved.
 *
 * This file is part of Gneat.
 *
 * Gneat is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License (LGPL)
 * as published by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Gneat is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * and the GNU General Public License, for completeness, along with Gneat.  
 * If not, see <http://www.gnu.org/licenses/>.
 */
package org.neatshell.gneat.client.presenter.core.traversing;

import org.neatshell.gneat.client.callback.CallbackListBoolean;
import org.neatshell.gneat.client.presenter.core.IPresenter;
import org.neatshell.gneat.client.presenter.core.IPresenterList;

public interface FilteringList {
	/**
	 * Add the previous set of elements on the stack to the current set.
	 * @return
	 */
	IPresenterList andSelf();

	boolean are();
	
	/**
	 * Check if this list contains each passed presenter
	 * @return true if each passed presenter is contained in this list, false if at least
	 * one of the passed presenters is not contained.
	 */
	boolean are(IPresenter... presenters);

	/**
	 * Check if this list contains each presenter contained in the passed list
	 * @return true if each presenter contained in the passed list is contained in this list,
	 * false if at least one presenter contained in the passed list is not contained in this list.
	 */
	boolean are(IPresenterList list);

	/**
	 * Reduce the current list of presenters to those at the specified indexes.
	 * @param indexes one or more integer indicating the 0-based position of the item.
	 * If <b>negative</b>, index indicate the position of the item, counting backwards 
	 * from the last item of the list
	 * @return 
	 */
	IPresenterList eq(Integer... indexes);
	
	/** End the most recent filtering operation in the current chain and return
	 *  the set of matched elements to its previous state.
	 *  
	 *  Gets the list to its previous state
	 */
	IPresenterList end();
	
	//End all the filtering operation in the current chain and return the set of matched
	//elements to its first state.
	//endAll();

	IPresenterList even();

//	/**
//	 * Get the first presenter contained in this list.
//	 * @return the first presenter of this list if not empty, null otherwise
//	 */
	IPresenter first();

//	IPresenterList filter(String... filters);

	IPresenterList filter(Integer nodeType);
	
	IPresenterList filter(CallbackListBoolean handler);
	
	/**
	 * 	Reduce the current list of presenters to those that have a descendant that matches the presenters.
	 */
	IPresenterList has(IPresenter... presenters);

	IPresenterList has(IPresenterList list);

	/**
	 * Check the presenters contained into the current list against the passed ones. The test passes
	 * if at least one presenter of the current list matches one of the passed.
	 * @param presenters one or more presenters to match the current list of presenters against
	 * @return true 
	 */
	boolean is(IPresenter... presenters);

	/**
	 * Check the presenters contained into the current list against the ones contained into the passed list.
	 * The test passes if one presenter of the current list matches a list's one.
	 * @param list a list of presenters to match the current list of presenters against.
	 * @return true is the test passes, false otherwise.
	 */
	boolean is(IPresenterList list);

//	/**
//	 * Get the last presenter of the current list.
//	 * @return the last presenter of this list if is not empty, null otherwise
//	 */
	IPresenter last();
	
	/**
	 * Reduce the current list of presenters to all but those at the specified indexes.
	 * @param indexes one or more integer indicating the 0-based position of the items.
	 * If <b>negative</b>, index indicate the position of the item, counting backwards 
	 * from the last item of the list.
	 * @return 
	 */
	IPresenterList neq(Integer... indexes);
	
	/**
	 * Get a reduced list containing all but those presenters that match the passed ones.
	 * @param presenters one or more presenters to match the current list of presenters against.
	 * @return a new list of presenters minus the matched ones.
	 */
	IPresenterList not(IPresenter... presenters);

	/**
	 * Get a reduced list containing all but those presenters that match the ones contained in the passed list.
	 * @param list a list of presenters to match the current list of presenters against.
	 * @return a new list of presenters minus the matched ones.
	 */
	IPresenterList not(IPresenterList list);

	IPresenterList odd();

	/**
	 * Get the reversed of the current list.
	 * @return a new list of presenters containing the same of the current but in a reversed order.
	 */
	IPresenterList reverse();
	
	/**
	 * Get a sliced list selecting only the presenters contained in the range specified by the 
	 * passed index and the end of the list.
	 * @param start an integer indicating the 0-based position at which the presenters begin to be selected.
	 * If negative, it indicates an offset from the end of the list.
	 * @return a new list of presenters sliced from the current one if a valid start index is provided, an empty
	 * list otherwise.
	 */
	IPresenterList slice(Integer start);

	/**
	 * Gets a sliced list selecting only the items contained in the range specified by the 
	 * passed indices. <b>Ascending</b> (start<end) and <b>Descending</b> (start>end) ranges are allowed, 
	 * in both cases the selection starts from the start index.
	 * @param start an integer indicating the 0-based position at which the presenters begin to be selected.
	 * If negative, it indicates an offset from the end of the list.
	 * @param end an integer indicating the 0-based position at which the presenters stop being selected.
	 * If negative, it indicates an offset from the end of the list
	 * @return a new list of presenters sliced from the current one if valid indices are provided, an empty
	 * list otherwise.
	 */
	IPresenterList slice(Integer start, Integer end);
}